package com.scw.service.serviceImp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.scw.dao.BasicDao;
import com.scw.model.SysUser;
import com.scw.service.UserService;


/**
 * 
 * @Description 用户信息service实现类
 * @author 王华聪
 * @version v1.0
 */
@Component("userService")
public  class UserServiceImp implements UserService {
	@Autowired
	private HibernateTemplate hibernateTemplate;
	
	public SysUser get(Long id) {
		SysUser user=null;
		user=(SysUser) getHibernateTemplate().get(SysUser.class, id);
		return user;
	}
	
	
	/**
	 * 登陆方法
	 */
	public SysUser login(SysUser sySUser) {
		String sql ="from SysUser t where t.user_name=? and t.password=?";
		List<SysUser> list=new ArrayList<SysUser>();
		list=getHibernateTemplate().find(sql,new Object[]{sySUser.getUser_name(),sySUser.getPassword()});
		if(list.size()>0){
			return list.get(0);
		}
		return null;
	}
	
	/**
	 * 添加用户
	 */
	public SysUser addUser(SysUser sysUser) {
		sysUser=(SysUser) getHibernateTemplate().save(sysUser);
		return sysUser;
	}
	
	/**
	 * 删除用户
	 */
	public void delUser(SysUser user) {
		getHibernateTemplate().delete(user);
	}
	
	/**
	 * 更新用户
	 */
	public SysUser updateUser(SysUser sysUser) {
		getHibernateTemplate().update(sysUser);
		return sysUser;
	}
	
	/**
	 * 模糊查找用户list
	 */
	public List<SysUser> getAllUser(SysUser sysUser){
		List<SysUser> list =new ArrayList<SysUser>();
		BasicDao<SysUser> bao=BasicDao.getDao(SysUser.class);
		list=bao.findall(sysUser);
		return list;
	}

	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	
	
}
